import { Application, AppStatus } from '../types'
import { isPromise } from '../utils/tool'

export default function mountApp(app: Application): Promise<any> {
	app.status = AppStatus.BEFORE_MOUNT

	let result = app.mount?.(app.props) as any
	if (!isPromise(result)) {
		result = Promise.resolve(result)
	}

	return result
		.then(() => {
			app.status = AppStatus.MOUNTED
		})
		.catch((err: Error) => {
			throw err
		})
}
